<template>
	<view>
		<view style="gap: 20rpx;">
			<view class="titleH3 fontWeight mtb20" style="color: #000;">
				{{options.title}}
			</view>
			<view v-for="([key, field]) in Object.entries(options.option)" :key="key"
				class="formitem borderbottom pv20">
				<view class="rowSpaceBetween">
					<view class="rowStart gap20 w100">
						<image :src="field.logo" class="logo" mode="widthFix"></image>
						<view class="title">
							{{field.title}}
						</view>
					</view>
					<view>
						<uv-input v-model="model[key]" :disabled="disabled" inputAlign="right" :placeholder="field.placeholder"
							border="none">
							<template v-slot:suffix>
								<view class="title mar20">
									{{field.unit}}
								</view>
							</template></uv-input>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import uploadView from '@/components/form/uploadView/uploadView.vue';
	export default {
		components: {
			uploadView,
		},
		props: {
			payRateInfo: {
				type: Object,
				default: () => {}
			},
			options: {
				type: Object,
				required: true,
			},
			disabled: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				model: {},
				rules: {},
			};
		},
		watch: {
			payRateInfo: {
				handler(newVal) {
					if (newVal) {
						this.model = newVal;
					}
				},
				deep: true
			}
		},
		computed: {
			// 动态生成表单验证规则
			fields() {
				return this.options;
			}
		},
		mounted() {
			// this.rules = this.generateRules();
		},
		methods: {
			// 生成验证规则
			generateRules() {
				return Object.fromEntries(Object.entries(this.fields).map(([key, field]) => {
					return field.validate ? [
						`userInfo.${key}`, {
							required: field.validate.required,
							message: `${field.title} 是必填项`,
							trigger: ['blur', 'change']
						}
					] : null;
				}).filter(Boolean));
			},
		}
	}
</script>

<style scoped lang="scss">
	.mar10 {
		margin: 10rpx;
	}

	::v-deep .uv-form-item__body__left__content__label {
		font-size: 26rpx;
	}

	.subTitle {
		font-size: 24rpx;
		color: var(--themeDefultFontColor);
		margin: 10rpx 0;
	}

	.logo {
		width: 40rpx;
		height: 40rpx;
	}

	.title {
		font-size: 26rpx;
	}

	.formitem {
		box-sizing: border-box;
	}

	.gap20 {
		gap: 20rpx;
	}

	.mar20 {
		margin: 0 20rpx;
	}
</style>